package com.guxingke.nioserver.exception;

/**
 * Created by guxingke on 15-8-18.
 */
public class ServerException extends Exception {
    private int errorCode;

    public ServerException(int errorCode) {
        this.errorCode = errorCode;
    }

    public int getErrorCode() {
        return errorCode;
    }

    @Override
    public String getMessage() {
        return getMsgByCode() == null ? super.getMessage() : getMsgByCode();
    }

    private String getMsgByCode() {
        String result = null;
        switch (errorCode) {
            // http
            case 404:
                result = "404 not found";
                break;
            case 500:
                result = "500 internal server error";
                break;
            // nio server
            case 600:
                result = "server some error ";
                break;
        }
        return result;
    }
}
